/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

/**
 *
 * @author melvinrafaelvegavega
 */

// vim: set expandtab tabstop=2 shiftwidth=2 fdm=marker:

public class Main {

    /**
     * @param args the command line arguments
     */
    
    public static void main(String[] args) { 
        // TODO code application logic here
        final Integer x;
        /*{{{ Main*/
        String cadenas[]=new String[50];
        final JTabbedPane jtp=new JTabbedPane();
        final JLabel jl[]=new JLabel[50];
        JFrame jx=new JFrame();
        jx.getContentPane().setLayout(null);
        jx.setBounds(0, 0, 500, 500);
        x=-1;
        final JTextArea jta;
        jta=new JTextArea();
        JPanel jp=new JPanel();
        JPanel jp2=new JPanel();
        /*}}} Main*/
        WindowListener l = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
	    System.exit(0);
        }
        };
        //Parser x;
        jx.addWindowListener(l);
        JMenuBar jmb=new JMenuBar();
        JMenu jm=new JMenu("Archivo");
        JMenuItem jmi=new JMenuItem("Abrir");
        final JMenuItem jmi2=new JMenuItem("Guardar");
        jmi2.setEnabled(false);
        jmi.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e)
           {
            JFileChooser fileChooser = new JFileChooser();
            int seleccion = fileChooser.showOpenDialog(jta);
            File fichero=null;
            if (seleccion == JFileChooser.APPROVE_OPTION)
            {
             fichero = fileChooser.getSelectedFile();
            }
            BufferedReader input;
            String line="";
            String cadena="";
            try {
            //System.out.print(fichero.getPath());
            jl[]=new JLabel(fichero.getName());
            jtp.add(fichero.getName(),jl[0]);
            System.out.print(jtp.getSelectedComponent().getName());
            input = new BufferedReader(new FileReader(fichero.getPath()));
            while ((line=input.readLine()) != null)
            { 
                cadena =cadena+"\n "+line;
            }
 
            input.close();
            }
            catch(IOException err) {
            //whatever you want it to do when you get an error
            }
            jta.setText(cadena);
            jta.setEnabled(true);
            jmi2.setEnabled(true);
           }
        });
        jm.add(jmi);
        jm.add(jmi2);
        jmb.add(jm);
        jmb.setAlignmentX(10);
        jmb.setBounds(0, 0, 500, 20);
        jtp.setBounds(0,25 , 500, 20);
        jtp.setAlignmentX(JTabbedPane.LEFT_ALIGNMENT);
        jta.setBounds(20, 50, 460, 460);
        JScrollPane scroll = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroll.setBounds(20, 50, 460, 460);
        JScrollBar scrollBar = new JScrollBar();
	scroll.setCorner(JScrollPane.LOWER_RIGHT_CORNER, scrollBar);
        jx.getContentPane().add(scroll);
        jx.getContentPane().add(jmb);
        jx.getContentPane().add(jtp);
        jx.setVisible(true);
        jta.setEnabled(false);
        }

}
